﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IRepository;
using Models;
using Infrastructures;
using System.Data;
using Spring.Data.Common;

namespace RepositoryMySQL
{
    public class UserValidationRepository : IUserValidationRepository
    {
        internal UserValidationRepository() { }

        public UserValidation Create(UserValidation obj)
        {
            string strIns = "INSERT INTO user_validation(User_ID, Account_Type, Account_Value, Valid_Type, Valid_No, Valid_Status, Created_Time, Updated_Time)"
                + " VALUES(@User_ID, @Account_Type, @Account_Value, @Valid_Type, @Valid_No, @Valid_Status, @Created_Time, @Updated_Time);" + DBHelper.GetLastInsertID;
            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();
            p.Add("User_ID", DbType.String).Value = obj.UserID;
            p.Add("Account_Type", DbType.String).Value = obj.AccountType.ToString();
            p.Add("Account_Value", DbType.String).Value = obj.AccountValue;
            p.Add("Valid_Type", DbType.String).Value = obj.ValidType.ToString();
            p.Add("Valid_No", DbType.String).Value = obj.ValidNo;
            p.Add("Valid_Status", DbType.String).Value = obj.ValidStatus;
            p.Add("Created_Time", DbType.DateTime).Value = DateTime.Now;
            p.Add("Updated_Time", DbType.DateTime).Value = DateTime.Now;

            int num = Int32.Parse(DBHelper.TemplateMySQL.ExecuteScalar(CommandType.Text, strIns, p).ToString());
            obj.ValidID = num;
            return obj;
        }
    }
}
